<template>
  <div class="download">
    <banner img="../assets/img/bg.jpeg" title="解决方案" />
    <div class="contentBox">
      <div class="menuBox">
        <div
          v-on:click="changeMenu(item)"
          :class="{
            menuItemed: subMenuId === item.id,
            menuItem: subMenuId != item.id
          }"
          v-for="(item, index) of menuList"
          :key="index"
        >
          {{ item.name }}
        </div>
      </div>

      <div style="width: 100%; padding-right: 80px">
        <div class="back">
          <span @click="goHome">首页></span>
          <span @click="getFirst">企业概况</span>
          <span
            v-if="menuList.length && !isList"
            @click="!isList ? (isList = true) : ''"
            >>{{ pageListContent.subMenuName }}></span
          >
          <span style="color: #a5a5a5" v-if="isList"
            >>{{ menuList.find((e) => e.id == subMenuId).name }}</span
          >
          <span style="color: #a5a5a5" v-if="!isList">{{
            pageListContent.title
          }}</span>
        </div>
        <div v-if="isList" class="menuContent" v-loading="loading">
          <div
            @click="goPageDetail(item)"
            class="menuContentItem"
            v-for="(item, index) of contentList"
            :key="index"
          >
            <div style="position: relative">
              <img
                v-if="item.top == 2"
                class="topImg"
                src="../assets/img/top.png"
                alt=""
                srcset=""
              />
              <span class="index" :style="{ color: item.top == 2 ? 'red' : '' }"
                >{{ query.pageNo * query.pageSize + (index + 1) }}.</span
              ><span
                class="title"
                :style="{ color: item.top == 2 ? 'red' : '' }"
                >{{ item.title }}</span
              >
            </div>
            <div style="color: #218fd1; font-weight: 700">
              <span
                style="color: #afa9a9; margin-right: 20px; font-size: 14px"
                >{{ getTimeTxt(item.createTime) }}</span
              >查看详情
            </div>
          </div>
          <el-pagination
            v-if="contentList.length > 0"
            style="margin-top: 40px; float: right"
            :page-size="10"
            layout="total, pager, next, jumper"
            :current-page="query.pageNo + 1"
            :total="query.total"
            @current-change="handleCurrentChange"
          />
        </div>

        <div v-if="!isList" class="pageListContent" v-loading="loading">
          <div style="width: 100%; text-align: center; position: relative">
            <span style="font-size: 20px; color: #333; font-wight: 700">{{
              pageListContent.title
            }}</span
            ><span style="color: #afa9a9; margin-left: 20px; font-size: 16px">{{
              getTimeTxt(pageListContent.createTime)
            }}</span>
          </div>
          <div style="margin-top: 30px" v-html="pageListContent.content"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getRoutes } from '../utils/auth'

import Banner from '../components/Banner'
export default {
  components: {
    Banner
  },
  data() {
    return {
      isList: true,
      pageListContent: {},
      loading: true,
      webImageList: [],
      solution: [],
      bannerHeight: '',
      menuList: [],
      contentList: [],
      query: {
        pageNo: 0,
        pageSize: 10,
        total: 0
      },
      subMenuId: '',
      pageTitle: '',
      menuId: 3
    }
  },
  mounted() {
    console.log(this.$route.name, '---------')
    getRoutes().map((res) => {
      if (this.$route.name == res.path) {
        this.pageTitle = res.name
      }
      console.log(res.path)
    })
  },
  created() {
    // console.log(getRoutes())
    this.$http
      .get(`/companyWeb/subMenu/list?menuId=${this.menuId}`)
      .then((responseCases) => {
        this.menuList = responseCases.data.obj.data
        this.menuList.unshift({
          id: '',
          name: '全部内容'
        })
        if (this.menuList.length > 0) {
          if (this.$route.params.subMenuId) {
            this.subMenuId = +this.$route.params.subMenuId
          } else {
            // this.subMenuId = this.menuList[0].id
          }
          this.getContentCreatedList()
        }
      })
  },
  methods: {
    getFirst() {
      location.reload()
    },
    goHome() {
      this.$router.push({
        path: '/'
      })
    },
    getTimeTxt(item) {
      return this.$dayjs(item).format('YYYY-MM-DD')
    },
    goPageDetail(item) {
      this.isList = false
      this.pageListContent = item
      // this.$router.push('/pageDetail')
    },
    getContentCreatedList() {
      let params = {}
      if (this.subMenuId) {
        this.$http
          .get(
            `/companyWeb/content/listConsumer?pageNo=${this.query.pageNo}&pageSize=${this.query.pageSize}&subMenuId=${this.subMenuId}`
          )
          .then((res) => {
            this.loading = false
            console.log(res.data.obj.data)
            this.contentList = res.data.obj.data
            this.contentList = res.data.obj.data
            this.pageListContent = this.contentList.find(
              (e) => e.id == this.$route.params.id
            )
            this.isList = false
            this.query.total = res.data.obj.count
          })
      } else {
        this.$http
          .get(
            `/companyWeb/content/listConsumer?pageNo=${this.query.pageNo}&pageSize=${this.query.pageSize}&menuId=${this.menuId}`
          )
          .then((res) => {
            this.loading = false
            console.log(res.data.obj.data)
            this.contentList = res.data.obj.data
            this.query.total = res.data.obj.count
          })
      }
    },
    getContentList() {
      let params = {}
      if (this.subMenuId) {
        this.$http
          .get(
            `/companyWeb/content/listConsumer?pageNo=${this.query.pageNo}&pageSize=${this.query.pageSize}&subMenuId=${this.subMenuId}`
          )
          .then((res) => {
            this.loading = false
            console.log(res.data.obj.data)
            this.contentList = res.data.obj.data
            this.query.total = res.data.obj.count
          })
      } else {
        this.$http
          .get(
            `/companyWeb/content/listConsumer?pageNo=${this.query.pageNo}&pageSize=${this.query.pageSize}&menuId=${this.menuId}`
          )
          .then((res) => {
            this.loading = false
            console.log(res.data.obj.data)
            this.contentList = res.data.obj.data
            this.query.total = res.data.obj.count
          })
      }
    },
    changeMenu(item) {
      this.isList = true
      this.query.pageNo = 0
      this.loading = !this.loading
      this.subMenuId = item.id
      this.getContentList()
    },
    handleCurrentChange(val) {
      this.query.pageNo = val - 1
      this.getContentList()
    }

    // goPage(item) {
    //   this.path = item
    //   this.$router.push(item)
    // }
  }
}
</script>

<style lang="scss" scoped>
.menuBox {
  padding-top: 40px;
}
.topImg {
  position: absolute;
  width: 20px;
}
.back {
  margin-left: 80px;
  margin-bottom: 20px;
  // color: #afa9a9;
  color: #333;

  display: flex;
  align-items: center;
  cursor: pointer;
}
.index {
  font-size: 16px;
  padding-left: 20px;
  margin-right: 10px;
  color: #333;
  font-weight: 700;
}
.title {
  font-size: 18px;
  margin-right: 10px;
  color: #333;
  font-weight: 700;
}
.download {
  width: 100%;
}
.menuContentItem {
  width: 100%;
  padding: 10px;
  border-bottom: 1px dotted #333;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.contentBox {
  width: 100%;
  padding: 0 120px;
  box-sizing: border-box;
  margin-top: 40px;
  margin-bottom: 180px;
  display: flex;
  align-items: flex-start;
  a {
    text-decoration: none;
    color: #333;
  }
  .menuItemed {
    width: 220px;
    height: 48px;
    font-size: 17px;
    font-weight: 700;
    line-height: 48px;
    text-align: center;
    background: #f0f0f0;
    box-shadow: 0 2px 12px 0 #d1cece;
    background: #218fd1;
    color: #fff;
    cursor: pointer;
  }
  .menuItem {
    cursor: pointer;
    width: 220px;
    height: 48px;
    line-height: 48px;
    font-size: 16px;
    text-align: center;
    background: #fff;
    box-shadow: 0 2px 12px 0 #d1cece;
  }
  .menuContent {
    width: 100%;
    margin-left: 80px;
  }
  .pageListContent {
    margin-left: 80px;
    width: 100%;
    padding: 10px 0;
  }
}
</style>